﻿@{
    Layout = "_EmptyLayout";
    ViewData["Title"] = "处理物资信息";
}
<div class="layui-container">
    <form class="layui-form layui-form-pane" action="" style="margin: 20px 15px" lay-filter="ShowHandleMaterialApply">
        <div class="layui-form-item">
            <label class="layui-form-label">申请人</label>
            <div class="layui-input-block">
                <input type="text" name="teacherName" lay-verify="title" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">申请物资</label>
            <div class="layui-input-block">
                <input type="text" name="goodsName" lay-verify="title" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物资数量</label>
            <div class="layui-input-block">
                <input type="text" name="goodsNum" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物资单价</label>
            <div class="layui-input-block">
                <input type="text" name="goodsPrice" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">申请人部门</label>
            <div class="layui-input-block">
                <input type="text" name="sectionName" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">申请原由</label>
            <div class="layui-input-block">
                <input type="text" autocomplete="off" class="layui-input" name="remarks" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">审批结果</label>
            <div class="layui-input-inline">
                <select name="state">
                    <option value="未处理">未处理</option>
                    <option value="同意">同意</option>
                    <option value="拒绝">拒绝</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit="" lay-filter="handleSubmit" id="button">确认</button>
        </div>
    </form>
</div>

@section Scripts{
    <script src="~/layui-v2.5.5/layui/layui.all.js" charset="utf-8"></script>
    <script src="~/js/jquery.js"></script>
    <script>
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , materialData = "";
                //表单赋值
                $.ajax({
                url: '/Api/ShowMaterialApply',
                data: { id: @ViewData["HMID"] },
                type: "GET",
                dataType: "JSON",
                success: function (data) {
                    switch (data.code) {
                        //奖励信息
                        case 200:
                            materialData = data;
                            form.val('ShowHandleMaterialApply', {
                            "teacherName": materialData.materialDetail.teacherName
                            , "goodsName": materialData.materialDetail.goodsName
                            , "goodsNum": materialData.materialDetail.goodsNum
                            , "goodsPrice": materialData.materialDetail.goodsPrice
                            , "sectionName": materialData.materialDetail.sectionName
                            , "remarks": materialData.materialDetail.remarks
                            , "state": materialData.materialDetail.state
                            });
                            break;
                        default:
                            layer.alert("数据异常，你再试试呗", { icon: 3 });
                    }
                    if (materialData.materialDetail.state != "未处理") {
                        var DomClass = document.getElementById("button").className;
                        DomClass = DomClass.replace('layui-btn',"layui-btn layui-btn-disabled");
                        document.getElementById("button").className = DomClass;
                    }
                }
                })
                //监听提交
                form.on('submit(handleSubmit)', function (data) {
                    //提交修改数据
                    $.ajax({
                        url: '/Api/SubmitHandleMaterialApply',
                        data: {
                            id: @ViewData["HMID"],
                            state: data.field.state
                        },
                        type: "POST",
                        dataType: "JSON",
                        success: function (data) {
                            switch (data.code) {
                                //奖励信息
                                case 0:
                                    layer.msg("审批成功，", { icon: 1 }, { time: 500 });
                                    setTimeout(function(){
                                        parent.window.location.reload();
                                    }, 500);
                                    break;
                                //惩罚信息
                                case 1:
                                    layer.alert("审批失败，",{ icon: 2 });
                                    break;
                                default:
                                    layer.alert("数据异常，你再试试呗", { icon: 3 });
                            }
                        },
                    })
                    return false;
                });
        });
    </script>
}
